<?php
/*
    OpenLib
    Copyright (C) 2011  Michael Gukov, Pham Thi Thuy Duong

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


namespace Sun;

final class Utils {
    private function __construct() {}

    public static function RandomString($len, $abc = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") {
        $str = "";
        for ($i = 0; $i < $len; ++$i)
        {
            $str .= $abc[rand() % strlen($abc)];
        }
        return $str;
    }

    public static function TrimArray(array $arr) {
        foreach ($arr as $i => $val) {
            if (is_string($val)) $arr[$i] = trim($val);
        }
        return $arr;
    }

    public static function LoadFileToString($file) {
        if (is_file($file)) {
            ob_start();
            include $file;
            $contents = ob_get_contents();
            ob_end_clean();
            return $contents;
        }
        return false;
    }

    public static function Date($date) {

    }

    public static function ValuesAt($arr, $keys) {
        $res = array();
        foreach ($keys as $key) {
            $res[$key] = $arr[$key];
        }
        return $res;
    }
}

